package nickthissen.iracing.datamodels;

import com.google.gson.Gson;

import org.apache.http.StatusLine;

import java.io.Serializable;

import nickthissen.iracing.networking.HttpResult;

public class Result extends ResultBase implements Serializable
{
	public Object Object;
    public StatusLine Status;

    public static Result fromJson(String json)
    {
        Gson g = new Gson();
        DataModel model = g.fromJson(json, DataModel.class);
        return model.d;
    }

    public static Result ok(HttpResult httpResult)
    {
        Result result = new Result();
        result.Object = httpResult.Contents;
        result.Status = httpResult.Status;
        result.Success = true;
        return result;
    }

	public static Result ok(Object object)
	{
		Result result = new Result();
		result.Object = object;
		result.Success = true;
		return result;
	}
	
	public static Result error(String message, Exception ex)
	{
		Result result = new Result();
		result.Object = null;
		result.Success = false;
		result.Message = message;
		result.DetailMessage = ex.toString();
		result.Exception = ex;
		return result;
	}

    public static Result failed()
    {
        Result result = new Result();
        result.Success = false;
        return result;
    }

    private class DataModel
    {
        public Result d;
    }
}
